package com.turtle3d.gui.toolbox;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.table.TableModel;

import com.turtle3d.formallanguage.symbol.SymbolFactory;

/**
 * <p>Toolbox GUI component.</p>
 * 
* <p>This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.</p>
*/
public class Toolbox extends javax.swing.JPanel {	
	private JTextField jTextField_Iterations;
	private JButton jButton_Go;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new Toolbox());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}	
	
	public Toolbox() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 1.0};
			thisLayout.rowHeights = new int[] {7, 7, 7, 7};
			thisLayout.columnWeights = new double[] {0.1, 0.1};
			thisLayout.columnWidths = new int[] {7, 7};
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(234, 300));
			{
				jTextField_Iterations = new JTextField();
				this.add(jTextField_Iterations, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				jTextField_Iterations.setText("7");
				jTextField_Iterations.setSize(100, 20);
				jTextField_Iterations.setPreferredSize(new java.awt.Dimension(100, 20));				
			}
			{
				jButton_Go = new JButton();
				this.add(jButton_Go, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				jButton_Go.setText("Go");
				jButton_Go.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {					
						GenerateFractalEvent generateFractalEvent = new GenerateFractalEvent();
						generateFractalEvent.setIterations(Integer.parseInt(jTextField_Iterations.getText()));						
						generateFractalListener.generate(generateFractalEvent);
					}
				});
			}			
			{
				TableModel jTable_ParametersModel = new ParameterTableModel(SymbolFactory.getSymbolFactory().getDefaultParameters());
				jTable_Parameters = new JTable();
				jTable_Parameters.setPreferredScrollableViewportSize(new Dimension(180,200));				
				/*this.add(jTable_Parameters, new GridBagConstraints(
					0,
					1,
					1,
					1,
					0.0,
					0.0,
					GridBagConstraints.CENTER,
					GridBagConstraints.NONE,
					new Insets(0, 0, 0, 0),
					0,
					0));*/
				jTable_Parameters.setModel(jTable_ParametersModel);
				jTable_Parameters.getColumnModel().getColumn(1).setPreferredWidth(40);
			}
			{
				jScrollPane_Parameters = new JScrollPane(jTable_Parameters);
				this.add(jScrollPane_Parameters, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
			}
			{
				jLabel_Iterations = new JLabel();
				this.add(jLabel_Iterations, new GridBagConstraints(
					0,
					0,
					1,
					1,
					0.0,
					0.0,
					GridBagConstraints.CENTER,
					GridBagConstraints.NONE,
					new Insets(0, 0, 0, 0),
					0,
					0));
				jLabel_Iterations.setText("Iterations:");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private GenerateFractalListener generateFractalListener;
	private JTable jTable_Parameters;
	private JLabel jLabel_Iterations;
	private JScrollPane jScrollPane_Parameters;

	public void setGenerateFractalListener(GenerateFractalListener generateFractalListener)
	{
		this.generateFractalListener = generateFractalListener;
	}
	
	


}
